package com.cy.service.factory;

import com.cy.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Usefulness: 用途
 * @Author: LeiTing
 * @Date: 2021/9/16  14:31
 * @Version 1.0
 */
@Slf4j //lombok中关于log的注解
@Component
public class RemoteProviderServiceFallbackFactory implements FallbackFactory<RemoteProviderService> {

    // org.slf4j.Logger是Java中的日志规范,定义了一组接口
    // org.slf4j.Logger这个接口的实现有log4j,logback
    //private static Logger log=
    //      LoggerFactory.getLogger(ProviderFallbackFactory.class);
    @Override
    public RemoteProviderService create(Throwable throwable) {

        log.error("用户服务调用失败:{}", throwable.getMessage());
//        return new RemoteProviderService() {
//            @Override
//            public String echoMessage(String msg) {
//                return "服务忙，请稍后访问！！！";
//            }
//        };
        return (msg)-> {//lambda (jdk中的一个表达式)
          return "服务忙，请稍后访问！！！";
        };
    }
}
